package com.kelvem.saas.workbanch.fsm.handle;

import com.kelvem.saas.workbanch.fsm.container.HandleContainer;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public abstract class Handle {
    
    private String name = "default";
    
    @Resource
    private HandleContainer handleContainer;
    
    public String getName() {
        return this.getClass().getSimpleName();
    }
    
    public abstract void execute();
    
    
    public Handle sync(Class<? extends Handle> handleClazz) {
        Handle handle = handleContainer.getHandle(handleClazz);
        handle.execute();
        return handle;
    }
    
    public Handle async(Class<? extends Handle> handleClazz) {
        Handle handle = handleContainer.getHandle(handleClazz);
        handle.execute();
        return handle;
    }
}
